<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree :treeData="treeData" :checkData="checkData" nodeKey="fCompanyid" @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps">
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left" style="width: 100%">
          <!-- <el-select class="selectBhz" v-model="getList.stationId" placeholder="所有拌和站" @change="selectBhz"
            style="width: 160px">
            <el-option v-for="v in bhzDataList" :key="v.fItemName" :label="v.fItemName" :value="v.fItemValue">
            </el-option>
          </el-select>
          <el-select class="selectBhz" v-model="getList.machineId" placeholder="所有拌和机" @change="yj_searchForm(getList)"
            style="width: 160px">
            <el-option v-for="v in bhjDataList" :key="v.fItemName" :label="v.fItemName" :value="v.fItemValue">
            </el-option>
          </el-select> -->

          <!-- <el-button type="primary" icon="el-icon-search" size="small" @click="yj_searchForm(getList)">查询 -->
          <!-- </el-button> -->
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button type="primary" icon="el-icon-refresh" size="small" @change="yj_searchForm(getList)">
            </el-button>
            <!-- <el-button
              type="primary"
              v-if="yj_view"
              icon="el-icon-search"
              size="small"
              @click="openDialog()"
              >查看
            </el-button> -->
            <el-button type="primary" icon="el-icon-search" size="small" @click="Print()">打印
            </el-button>
          </div>
        </div>
      </div>
      <!-- 表格 -->
      <div class="text_table">
        <tableData :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'" :config="table_config"
          :dataList="tableData" :loading="loading" @selection-change="selectionChange" @sort-change="sortChange"
          @click-change="rowChange" @ClickOnLine="yj_viewForm" :page="getList.page" :pageSize="getList.pageSize" />
        <pagination :info="queryCriteriaData" v-if="navigatepageNums > 1" :treelength="treelength"
          :total="queryCriteriaData.total" :pageNum.sync="getList.page" :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)" />
      </div>

      <!--配合比通知单编号弹框 查看 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog :title="dialogTitle" :modal-append-to-body="false" v-dialogDrag :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: '650px' }" style="overflow: hidden">
            <div style="overflow-y: auto; margin-bottom: 20px">
              <div class="baseTitle">检验申请</div>
              <div class="publicForm" style="height: 220px">
                <publicForm ref="publicForm" lableWidth="125px" :formObj="formObjText" :formData="formData"
                  :timestamp="formData.fHandlefile" :fileList="fHandlefileList" @delteFile="delteFile"
                  @inputFocus="inputFocus">
                </publicForm>
              </div>
              <div class="baseTitle" v-if="firstNum">监理员意见</div>
              <div class="publicForm" style="height: 100px" v-if="firstNum">
                <publicForm ref="publicForm1" lableWidth="125px" :formObj="formObjText1" :formData="formData"
                  :timestamp="formData.fQualityfile" :fileList="fQualityfileList" @delteFile="delteQualityFile"
                  @inputFocus="inputFocus">
                </publicForm>
              </div>
              <div class="baseTitle" v-if="secondNum">监理工程师审批</div>
              <div class="publicForm" style="height: 80px" v-if="secondNum">
                <publicForm ref="publicForm2" lableWidth="125px" :formObj="formObjText2" :formData="formData">
                </publicForm>
              </div>
              <div class="baseTitle" v-if="threeLevel">施工单位签收</div>
              <div class="publicForm" style="height: 100px" v-if="threeLevel">
                <publicForm ref="publicForm3" lableWidth="125px" :formObj="formObjText3" :formData="formData">
                </publicForm>
              </div>
            </div>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
  
<script>
import tree from "@/components/siteQualityPage/QualityGridManage/tree"; //左侧机构树
import TableData from "@/components/stationProductionPage/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  getWorkProcessDescriptionLists, //主页面列表接口
  getWorkProcessDescriptionByFid, //详情
} from "@/api/request.js";

export default {
  name: "ProcessInspection",
  data() {
    return {
      name: "ProcessInspection", //按钮配置页面代号
      yj_view: null,
      projectName: [], //下拉框项目名称
      LotName: [], //下拉框标段名称
      bhzDataList: [], //拌合站
      bhjDataList: [], //拌合机

      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页

      // 列表
      getList: formJs.getList,
      loading: false, //列表转载
      fId: null, //当前行数据fId
      table_config: formJs.table_config,
      tableData: [], //表格列表数据列表
      row: null, //当前行
      // 列表

      // 弹框
      timeYMD: null, //当前日期
      btnShow: true,
      disabled: false,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      formObjText: null,
      formObjText1: null,
      formObjText2: null,
      formObjText3: null,
      formObj: formJs.formObj, //信息编辑配置参数
      formObjs: formJs.formObjs, //信息查看配置参数
      formObjFirst: formJs.formObjFirst, //信息编辑配置参数
      formObjFirsts: formJs.formObjFirsts, //信息查看配置参数
      formObjFirst2: formJs.formObjFirst2, //信息编辑配置参数
      formObjFirst2s: formJs.formObjFirst2s, //信息查看配置参数
      formObjFirst3: formJs.formObjFirst3, //信息编辑配置参数
      formObjFirst3s: formJs.formObjFirst3s, //信息查看配置参数
      formData: formJs.formData,
      recordfiles: [], //删除文件
      fSourcefileList: [],
      stationfileList: [],
      saveData: formJs.saveData,
      // 弹框

      // 弹框2
      loadingEditDialogSC: false, //弹框loading
      dialogEditVisibleSC: false, //新增弹框是否显示
      isShow: false,
      navigatepageNums1: null, //是否显示分页
      queryCriteriaData1: {}, //分页
      tableData1: [],
      tableList: {
        companyid: "", // 施工标段id
        taskNumber: "",
        page: 1, // 当前页码
        pageSize: 3, // 每页显示条数
      },
      // 弹框2

      // 机构树
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
      },
      checkData: [], //树状图默认选中id
      // 机构树

      userInfo: {}, //登录用户
    };
  },
  components: {
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    publicForm, //弹框表格
    Pagination, //分页
  },
  mounted() {
    this.getList.modelType = "2";
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
    if (JSON.parse(sessionStorage.getItem("yjSmart-getList"))) {
      var getListStorage = JSON.parse(sessionStorage.getItem("yjSmart-getList"));
      this.getList.fCompanyid = getListStorage.fCompanyid;
    }
    if (JSON.parse(sessionStorage.getItem("yjSmart-Quality_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("yjSmart-Quality_treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);

    this.table_config.operation.cols = [
      {
        prop: "fStatus",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];
    // this.table_config.operation["specialClass"] = function (rowData) {
    //   var color = null;
    //   if (rowData == "未提交") {
    //     color = "red !important";
    //   } else if (rowData == "生产中") {
    //     color = "#409eff !important";
    //   } else if (rowData == "运输中") {
    //     color = "#e6a23c  !important";
    //   } else {
    //     color = "green !important";
    //   }
    //   return color;
    // };
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_view = btnStr.includes("yj_view");
      } else {
        this.yj_view = true;
      }
    },
    // 左侧树结构
    getTree() {
      this.treeText.companyId = this.userInfo.companyId;
      this.treeText.userId = this.userInfo.userId;
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-Quality_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
              this.checkData[0] = this.treeData[0].fCompanyid;
            }
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getList.fCompanyid = data.fCompanyid;
      this.getList.projectId = ""; //项目ID
      this.getList.companyId = ""; //标段ID
      this.getList.page = 1;
     
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(id) {
      this.loading = true;
      // var newData = {};
      // window.sessionStorage.setItem("yjSmart-getList", JSON.stringify(newData));
      getWorkProcessDescriptionLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          console.log("列表");
          this.loading = false;
        });
    },
    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 点击查看
    yj_viewForm(row) {
      this.fId = row.fId;
      this.editText(this.fId);
    },
    // 查看
    editText(id) {
      this.formObjText = this.formObj;
      this.formObjText1 = this.formObjFirst;
      this.formObjText2 = this.formObjFirst2;
      this.formObjText3 = this.formObjFirst3;

      this.dialogTitle = "查看";
      this.btnShow = false;
      this.firstNum = false; //监理员意见显示
      this.secondNum = false; //监理工程师审批显示
      this.threeLevel = false; //施工单位签收显示


      this.disabled = true;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getWorkProcessDescriptionByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loadingEditDialog = false;
              this.formData = res.data.WorkprocessDescription;
              this.fHandlefileList = res.data.fHandlefileList;
              this.fQualityfileList = res.data.fQualityfileList;

              this.btnShow = true;
              if (this.formData.fStatus == "审核中") {
                this.firstNum = true; //监理员意见显示
              }
              if (this.formData.fStatus == "审批中") {
                this.firstNum = true; //监理员意见显示
                this.secondNum = true; //监理工程师审批显示
              }
              if (this.formData.fStatus == "签收中") {
                this.firstNum = true; //监理员意见显示
                this.secondNum = true; //监理工程师审批显示
                this.threeLevel = true; //施工单位签收显示
              }
              if (this.formData.fStatus == "已完成") {
                this.firstNum = true; //监理员意见显示
                this.secondNum = true; //监理工程师审批显示
                this.threeLevel = true; //监理员意见显示
              }
              this.formObjText.map((item) => {
                //工程报验单
                item.disabled = true; //工程报验单禁用
                item.uploadSelect = false; //上传附件按钮是否显示
                item.rules = []; //必填项不必填
              });

              this.formObjText1.map((item) => {
                //工程报验单
                item.disabled = true; //工程报验单禁用
                item.uploadSelect = false; //上传附件按钮是否显示
                item.rules = []; //必填项不必填
              });
              this.formObjText2.map((item) => {
                //工程报验单
                item.disabled = true; //工程报验单禁用
                item.uploadSelect = false; //上传附件按钮是否显示
                item.rules = []; //必填项不必填
              });
              this.formObjText3.map((item) => {
                //工程报验单
                item.disabled = true; //工程报验单禁用
                item.uploadSelect = false; //上传附件按钮是否显示
                item.rules = []; //必填项不必填
              });
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
    // 折叠面板
    changeCollapse(e) {
      console.log(this.activeNames, e);
    },
    // 刪除
    delteFile(file) {
      console.log("刪除文件", file);
      console.log("fSourcefileList111", this.fSourcefileList);
      for (let index = 0; index < this.fSourcefileList.length; index++) {
        if (file.uid == this.fSourcefileList[index].uid) {
          if (this.fSourcefileList[index].atta == undefined) {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].fId,
            });
          } else {
            this.recordfiles.push({
              fId: this.fSourcefileList[index].atta.fId,
            });
          }
          this.fSourcefileList.splice(index, 1);
        }
      }
      console.log("fSourcefileList222", this.fSourcefileList);
      console.log("recordfiles", this.recordfiles);
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    indexMethod(index) {
      return index + 1 + (this.tableList.page - 1) * 3; // page是当前的页码，size是页码容量
    },
    getDate() { },
    // 获取页面容器高度
    getHeight() {
      // var h = document.documentElement.clientHeight; //获取页面可见高度
    },

    selectionChange() { },
    // 排序方法
    sortChange() { },
  },
};
</script>
  
<style scoped >
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

/* 砼配合比表格 */
.mixProportion {
  width: 100%;
  height: 150px;
  margin: 20px 0;
  border-top: 1px solid #ccc;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
}

.titleBig {
  width: 100%;
  height: 60px;
  border-bottom: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
}

.title {
  height: 100%;
  width: 8%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid #ccc;
  font-size: 12px;
  font-weight: 700;
}

.title1 {
  display: flex;
  flex-direction: column;
}

.title1_1 {
  width: 100%;
  height: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 1px solid #ccc;
}

.title1_2 {
  width: 100%;
  height: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.title1_2_1 {
  width: 33%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-left: 1px solid #ccc;
}

.title1_2_2 {
  width: 50%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-left: 1px solid #ccc;
}

.titleSmall {
  width: 100%;
  height: 30px;
  border-bottom: 1px solid #ccc;
  /* background: #0c204d; */
  display: flex;
}

.title2 {
  width: 8%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  border-left: 1px solid #ccc;
}

.titleSmall /deep/ .el-input__inner {
  height: 27px !important;
  line-height: 26px !important;
  text-align: center;
  border: none;
}

.titleSmall /deep/ .el-input {
  line-height: 28px !important;
}

/* 砼配合比表格 */
/* 任务单弹框 */
.Multi_level_header /deep/.el-table__body-wrapper tr {
  height: 80px !important;
}

.Multi_level_header /deep/.el-table__body-wrapper .lineBoxhidden {
  height: 64px !important;
  line-height: 22px !important;
}

.Multi_level_header /deep/.el-table .el-table__body-wrapper .cell {
  height: 100% !important;
}

.materialClass /deep/.el-table tr:nth-child(4) {
  display: none;
}

#materialPage /deep/ .bgwarn2 {
  background: #e6a23c !important;
  color: #fff !important;
}

#materialPage /deep/ .bgwarn1 {
  background: #409eff !important;
  color: #fff !important;
}

#materialPage /deep/ .bgwarn3 {
  background-color: #f56c6c !important;
  color: #fff !important;
}

#materialPage /deep/ .bgwarn4 {
  background-color: rgb(212, 179, 137) !important;
  color: #fff !important;
}

/* 任务单弹框 */
</style>
